/* BEGIN itoa.c */  



#include "itoa.h"

static char *sput_i(int, char *);
static char *sput_ip1(int, char *);

void itoa(int integer, char *string)
{
  if (0 > integer) {  
    ++integer;
    *string++ = '-';
    *sput_ip1(-integer, string) = '\0';
  } else {
   *sput_i(integer, string) = '\0';
  }
}

char *sput_i(int integer, char *string)
{
  if (integer / 10 != 0) {
    string = sput_i(integer / 10, string);
  }
  
  *string++ = (char)('0' + integer % 10); 
  return string;
}

char *sput_ip1(int integer, char *string)
{
  int digit;

  digit = (integer % 10 + 1) % 10;
  if (integer / 10 != 0) 
  {
    string = (digit == 0 ? sput_ip1 : sput_i)(integer / 10, string);
    *string++ = (char)('0' + digit);
  } 
  else
  {
    if (digit == 0) 
    {
      *string++ = '1';
    }
    
    *string++ = (char)('0' + digit); 
  }
  
  return string;
}

/* END itoa.c */